Remove duplicates with pandas

126

Remove duplicates with pandas -

import pandas as pd

# Drop all duplicates in the DataFrame
df = df.drop_duplicates()

# Drop all duplicates in a specific column of the DataFrame
df = df.drop_duplicates(subset = "column")

# Drop all duplicate pairs in DataFrame
df = df.drop_duplicates(subset = ["column", "column2"])

# Display DataFrame
print(df)

df index drop duplicates -

df3 = df3[~df3.index.duplicated(keep='first')]

Comments

Submit
0 Comments